<?php
/**
 * 积分礼品管理
 * @author hushuai
 *
 */
class IntegralAction extends CommonAction {
	 
	private $Integra = "Integral";           //定义积分礼品表
	private $OIView  = "OutletIntegralView"; //定义餐厅积分礼品关联视图
 
    /**
     * 初始化
     */
    public function _initialize(){
    
    	parent::_initialize();
    	//parent::checkTimestamp();
    }
    
    /**
     * 查询积分礼品（分页）
     */
    public function index(){
    	 
    	$desc     = $this->_get("orderDirection", "trim",   "desc");;
    	$order    = $this->_get("orderName",      "trim",   "addtime");
    	$pageNum  = $this->_get("pageNum",        "intval", C('PAGE_NUMS'));
    	$nowPage  = $this->_get("p",              "intval", 1);
    	$where    = $_POST['where'];
    	if($where){
    		foreach ($where as $k=>$v){
    			if($v){
    				$map['d.'.$k] = $v;
    			}
    		}
    	}
    	$map['d.isdel'] = 2 ;
    	$con      = $order.' '.$desc;
    	$table    = $this->OIView; 
		
    	$this->success(parent::pageSelect($table,$map,$pageNum,$nowPage,$con));
    }
    
    /**
     * 查询积分礼品（无分页）
     */
    public function dview(){
    	$data = D($this->OIView)->where("d.isdel=2")->select();
    	$this->success($data);
    } 
    
    /**
     * 添加积分礼品
     */
    public function add(){
    	
    	parent::do_add($this->Integra);
    
    }
    /**
     * 修改积分礼品
     */
    public function edit(){
    	
    	parent::do_edit($this->Integra);
    
    }
    
    /**
     * 查询餐厅积分礼品关联详情
     */
     public function detail(){
    
    	$id = $this->_get("id","intval",0);
    	$data  = D($this->OIView)->where("d.id=".$id)->find();
    	$this->success($data);
    
    } 
    
    /**
     * 删除积分礼品
     */
    public function del(){
    
    	$id    = $this->_get("id","intval",0);
    	$maps = array("id"=>$id,"isdel"=>1);
    	M($this->Integra)->save($maps);
    }
    
    /**
     * 批量删除积分礼品
     */
    public function delall(){
    	 
    	$val = $this->_req("val","trim","");
    	if($val){
    		 
    		$idArr = explode(',',$val);
    		foreach($idArr as $k=>$v){
    			 
    			$map['id']    = $v;
    			$map['isdel'] = 1;
    			$data = M($this->Integra)->save($map);
    		}
    	}
    	
    	if($data){
    		$this->success($data);
    	}else{
    		$this->error("请选择您要删除的积分礼品");
    	}
    	
    }
    
    /**
     * 积分礼品分类有子类
     */
    public function view(){
    	 
    	$map = array("isdel"=>2,"issub"=>1);
    	$this->success(M($this->tabltableDisheseDishsort)->where($map)->select());
    
    }
    
    /**
     * 积分礼品分类无分页查询
     */
    public function select(){
    
    	$map = array("isdel"=>2);
    	 
    	$this->success(M($this->tableDishsort)->where($map)->select());
    
    }
    
    /**
     * 根据id查询
     */
    public function find(){
    
    	$id = $this->_get("id","intval",0);
    
    	$this->success(M($this->tableDishsort)->find($id));
    
    }
}